package com.define.ssh.util;

import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 字符串操作类 包括金额转换、类型转换、时间转换等
 * 
 * @author xufc
 * 
 */
public class StringUtil {

	public static int getIntValue(Object obj) {
		if (obj == null || obj.equals(""))
			return 0;
		else
			return Integer.parseInt(obj.toString());
	}

	/**
	 * 尝试把Object转换为double，失败返回0.0，不报错
	 * 
	 * @param obj
	 *            Object
	 * @return double
	 */
	public static double getDoubleValue(Object obj) {
		try {
			return Double.parseDouble(obj.toString());
		} catch (final Exception e) {
			return 0.0;
		}
	}

	/**
	 * 检查输入字符串
	 * 
	 * @param strin
	 *            String 输入字符串
	 * @return String 如果输入字符串为空,则返回空字符串,否则返回去除空格的字符串.
	 */
	public static String getTrimString(String strin) {
		if (strin == null) {
			strin = "";
		} else {
			strin = strin.trim();
		}

		if (strin.equals("")) {
			strin = "";
		}
		return strin;
	}

	/**
	 * 检查输入对象,是否字符串
	 * 
	 * @param o
	 *            Object 输入对象
	 * @return String 如果输入对象是字符串,且字符串为空,则返回空字符串,否则返回去除空格的字符串.
	 */
	public static String getString(Object o) {

		String strv = "";
		try {

			if (o == null) {
				strv = "";
			} else {
				strv = ((String) o);
			}
		} catch (final Exception ex) {

		}

		return strv;
	}

	/**
	 * 检查输入对象,是否字符串
	 * 
	 * @param o
	 *            Object 输入对象
	 * @return String 如果输入对象是字符串,且字符串为空,则返回空字符串,否则返回去除空格的字符串.
	 */
	public static String getTrimString(Object o) {
		String strv = "";
		if (o == null) {
			strv = "";
		} else {
			strv = o.toString().trim();
		}

		return strv;
	}

	public static String moneyFormatStr2(double total) {

		String ret = "";

		try {

			total = round(total, 2);

			final java.text.DecimalFormat decimalFormat = new java.text.DecimalFormat(
					"####0.00");

			ret = decimalFormat.format(Math.round(total * 100) / (double) 100);

		} catch (final Exception ex) {

			ex.printStackTrace();

			ret = "0.00";

		}

		return ret;
	}

	public static String handleNumber(Object obj) {
		if (obj == null)
			return "0";
		if (obj.toString().equals(""))
			return "0";
		if (obj.toString().equals("null"))
			return "0";
		else
			return obj.toString();
	}

	public static String handleNumber2(Object obj) {
		if (obj == null)
			return "0.00";
		if (obj.toString().equals("0"))
			return "0.00";
		if (obj.toString().equals("0.0"))
			return "0.00";
		if (obj.toString().equals(""))
			return "0.00";
		if (obj.toString().equals("null"))
			return "0.00";
		else
			return obj.toString();
	}

	/**
	 * 提供精确的小数位四舍五入处理。
	 * 
	 * @param v
	 *            需要四舍五入的数字
	 * @param scale
	 *            小数点后保留几位
	 * @return 四舍五入后的结果
	 */
	public static double round(double v, int scale) {

		if (scale < 0) {
			throw new IllegalArgumentException("参数必须大于0");
		}
		final BigDecimal b = new BigDecimal(Double.toString(v));
		final BigDecimal one = new BigDecimal("1");
		return b.divide(one, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
	}

	public static double moneyFormatDouble2(double total) {

		double ret = 0;

		try {

			ret = round(total, 2);

		} catch (final Exception ex) {

			ex.printStackTrace();

			ret = 0;

		}

		return ret;
	}

	public static double moneyFormatDouble4(double total) {

		double ret = 0;

		try {

			ret = round(total, 4);

		} catch (final Exception ex) {

			ex.printStackTrace();

			ret = 0;

		}

		return ret;
	}

	public static double moneyFormatDouble6(double total) {

		double ret = 0;

		try {

			ret = round(total, 6);

		} catch (final Exception ex) {

			ex.printStackTrace();

			ret = 0;

		}

		return ret;
	}

	/**
	 * 检测输入字符串是否浮点数
	 * 
	 * @param strv
	 *            String 输入字符串
	 * @return int 如果输入字符串是浮点数,则把字符串转换为浮点数,并返回
	 */
	public static double getDouble(Object str) {

		final String strv = getTrimString(str);
		double dret = 0;
		if (strv == null || strv.equals("null") || strv.equals("")) {
			dret = 0;
		} else {
			try {

				dret = Double.parseDouble(strv);
			} catch (final Exception e) {
				System.err.println("str=" + str);
				e.printStackTrace();
				dret = 0;
			}
		}
		return dret;

	}

	/**
	 * 检测输入字符串是否浮点数
	 * 
	 * @param strv
	 *            String 输入字符串
	 * @return int 如果输入字符串是浮点数,则把字符串转换为浮点数,并返回
	 */
	public static String getDouble_1(String str) {
		String retlStr = null;
		if (str != null && !"".equals(str)) {
			final double d = Double.parseDouble(str);
			if (d != 0) {
				retlStr = d + "";
			}
		}
		return retlStr;
	}

	/**
	 * 字符串转换为两位小数的数字
	 * 
	 * @param sObj
	 * @return
	 */
	public static String getStringFromDouble(String sObj) {
		String sNewObj = "";
		String sInteger = "";// 整数部分
		String sDecimal = "";// 小数部分
		if (sObj.length() > 2) {
			sInteger = sObj.substring(0, sObj.length() - 2);
			sDecimal = sObj.substring(sObj.length() - 2, sObj.length());
			sNewObj = sInteger + "." + sDecimal;
		} else {
			sNewObj = "0.00";
		}
		return sNewObj;

	}

	/**
	 * 检测输入字符串是否整数
	 * 
	 * @param strv
	 *            String 输入字符串
	 * @return int 如果输入字符串是整数,则把字符串转换为整数,并返回
	 */
	public static int getInt(Object str) {
		String strv = getTrimString(str);
		int iret = 0;
		if (strv == null) {
			iret = 0;
		} else {
			try {
				if (strv.indexOf(".") > 0) {
					strv = strv.substring(0, strv.indexOf("."));
				}
				iret = Integer.parseInt(strv);
			} catch (final Exception e) {
				iret = 0;
			}
		}
		return iret;
	}

	public static long getLong(Object str) {
		String strv = getTrimString(str);
		long iret = 0;
		if (strv == null) {
			iret = 0;
		} else {
			try {
				if (strv.indexOf(".") > 0) {
					strv = strv.substring(0, strv.indexOf("."));
				}
				iret = Long.parseLong(strv);
			} catch (final Exception e) {
				iret = 0;
			}
		}
		return iret;
	}

	/**
	 * 检测输入对象是否整数
	 * 
	 * @param obj
	 *            Object 输入对象
	 * @return String 如果输入对象是整数,则把输入对象转换为整数,并返回
	 */
	public static String getIntString(Object obj) {
		int iret = 0;
		if (obj == null) {
			iret = 0;
		} else {
			try {
				String strv = (String) obj;
				if (strv.indexOf(".") > 0) {
					strv = strv.substring(0, strv.indexOf("."));
				}
				iret = Integer.parseInt(strv);
			} catch (final Exception e) {
				iret = 0;
			}
		}
		return String.valueOf(iret);
	}

	/**
	 * 取应用服务器日期,返回<=0为失败
	 * 
	 * @return long 返回应用服务器的日期,例如:20070128
	 * @throws JOBExp
	 */
	public static long getDate() throws Exception {
		long lret = -1;
		String strdate = "0";
		final Date today = new Date();
		DateFormat todayfmt = null;
		String stryear = "", strmonth = "", strday = "";
		try {
			todayfmt = DateFormat.getDateInstance(DateFormat.MEDIUM);
			strdate = todayfmt.format(today);
			stryear = strdate.substring(0, strdate.indexOf("-"));
			strdate = strdate.substring(strdate.indexOf("-") + 1);
			strmonth = strdate.substring(0, strdate.indexOf("-"));
			strdate = strdate.substring(strdate.indexOf("-") + 1);
			strday = strdate.substring(strdate.indexOf("-") + 1);
			if (strmonth.length() == 1) {
				strmonth = "0" + strmonth;
			}
			if (strday.length() == 1) {
				strday = "0" + strday;
			}
			lret = Long.parseLong(stryear + strmonth + strday);

		} catch (final Exception ex) {
			lret = -1;
		} finally {
		}
		return lret;
	}

	/**
	 * 取应用服务器年份,返回<=0为失败
	 * 
	 * @return long 取应用服务器年份,例如:2007
	 * @throws JOBExp
	 */
	public static long getYear() {
		long lret = -1;
		String strdate = "0";
		final Date today = new Date();
		DateFormat todayfmt = null;
		String stryear = "";
		try {
			todayfmt = DateFormat.getDateInstance(DateFormat.MEDIUM);
			strdate = todayfmt.format(today);
			// SCom.printDebugLog(strdate);
			// SCom.printDebugLog(strdate.indexOf("-")+"");
			stryear = strdate.substring(0, strdate.indexOf("-"));
			lret = Long.parseLong(stryear);

		} catch (final Exception ex) {
			lret = -1;
		} finally {
		}
		return lret;
	}

	/**
	 * 对输入日期进行格式化
	 * 
	 * @param date
	 *            String 输入日期,例如:20070202; 200702; 200702-200712,20070202123040
	 * @return String 输出日期,例如:2007年02月02日;2007年02月;2007年02月-2007年12月
	 */
	public static String formatDate(String date) {

		final StringBuffer buff = new StringBuffer();
		if (date == null || date.equals("0")) {
			return "---";
		} else {
			if (date.length() == 6) { // 6位日期格式
				buff.append(date.substring(0, 4) + "年");
				buff.append(date.substring(4, 6) + "月");
			}
			if (date.length() == 8) { // 8位日期格式
				buff.append(date.substring(0, 4) + "年");
				buff.append(date.substring(4, 6) + "月");
				buff.append(date.substring(6, 8) + "日");
			}
			if (date.length() == 13) { // 13位日期格式
				buff.append(date.substring(0, 4) + "年");
				buff.append(date.substring(4, 6) + "月");
				buff.append("-");
				buff.append(date.substring(7, 11) + "年");
				buff.append(date.substring(11, 13) + "月");
			}
			if (date.length() == 14) { // 14位日期格式
				buff.append(date.substring(0, 4) + "年");
				buff.append(date.substring(4, 6) + "月");
				buff.append(date.substring(6, 8) + "日");
			}

		}
		return buff.toString();
	}

	/**
	 * 对输入日期进行格式化
	 * 
	 * @param date
	 *            String 输入日期,例如: 20070202123040
	 * @return String 输出日期,例如:2007年02月02日;2007年02月;2007年02月-2007年12月
	 */
	public static String formatFullDateTime(String date) {

		final StringBuffer buff = new StringBuffer();
		if (date == null || date.equals("0")) {
			return "";
		} else {
			if (date.length() >= 14) {
				buff.append(date.substring(0, 4) + "-")
						.append(date.substring(4, 6) + "-")
						.append(date.substring(6, 8) + " ")
						.append(date.substring(8, 10) + ":")
						.append(date.substring(10, 12) + ":")
						.append(date.substring(12, 14));
			} else if (date.length() == 8) {
				buff.append(date.substring(0, 4) + "-")
						.append(date.substring(4, 6) + "-")
						.append(date.substring(6, 8) + " ").append("00:00:00");

			}

		}
		return buff.toString();
	}

	/**
	 * 从输入日期中,获取年份
	 * 
	 * @param date
	 *            String 输入时间,例如:200702021224
	 * @return int 输出年份,例如:2007
	 */
	public static int getYearFrmStr(String date) {
		final StringBuffer buff = new StringBuffer();
		if (date == null || date.equals("0")) {
			return 0;
		} else {
			date = getTrimString(date);
			if (date.length() == 8 || date.length() == 12) { // 8位日期格式
				buff.append(date.substring(0, 4));
			} else {
				return 0;
			}
		}
		return Integer.parseInt(buff.toString());
	}

	/**
	 * 从输入日期中,获取月份
	 * 
	 * @param date
	 *            String 输入时间,例如:"20070212" 或者 "200702021224"
	 * @return int 输出月份,例如:2
	 */
	public static int getMonthFrmStr(String date) {
		final StringBuffer buff = new StringBuffer();
		if (date == null || date.equals("0")) {
			return 0;
		} else {
			date = getTrimString(date);
			if (date.length() == 8 || date.length() == 12) { // 8位日期格式
				buff.append(date.substring(4, 6));
			} else {
				return 0;
			}
		}
		return Integer.parseInt(buff.toString());
	}

	/**
	 * 从输入日期中,获取日份
	 * 
	 * @param date
	 *            String 输入时间,例如:"20070212" 或者 "200702021224"
	 * @return int 输出日份,例如:2
	 */
	public static int getDayFrmStr(String date) {
		final StringBuffer buff = new StringBuffer();
		if (date == null || date.equals("0")) {
			return 0;
		} else {
			date = getTrimString(date);
			if (date.length() == 8 || date.length() == 12) { // 8位日期格式
				buff.append(date.substring(6, 8));
			} else {
				return 0;
			}
		}
		return Integer.parseInt(buff.toString());
	}

	/**
	 * 从输入日期中,获取小时
	 * 
	 * @param date
	 *            String 输入时间,例如:"200702021224"
	 * @return int 输出日份,例如:12
	 */
	public static int getHourFrmStr(String date) {
		final StringBuffer buff = new StringBuffer();
		if (date == null || date.equals("0")) {
			return 0;
		} else {
			date = getTrimString(date);
			if (date.length() == 12) { // 8位日期格式
				buff.append(date.substring(8, 10));
			} else {
				return 0;
			}
		}
		return Integer.parseInt(buff.toString());
	}

	/**
	 * 从输入日期中,获取分钟
	 * 
	 * @param date
	 *            String 输入时间,例如:"200702021224"
	 * @return int 输出分钟,例如:24
	 */
	public static int getMinFrmStr(String date) {
		final StringBuffer buff = new StringBuffer();
		if (date == null || date.equals("0")) {
			return 0;
		} else {
			date = getTrimString(date);
			if (date.length() == 12) { // 8位日期格式
				buff.append(date.substring(10, 12));
			} else {
				return 0;
			}
		}
		return Integer.parseInt(buff.toString());
	}

	/**
	 * 获取当前应用系统的日期
	 * 
	 * @return String 当前应用系统的日期,例如:200722
	 */
	public static String getCurrentDate() {
		String strTime = "-1";
		try {
			final Date date = new Date();
			final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
			strTime = dateFormat.format(date);

		} catch (final Exception e) {
			e.fillInStackTrace();
		}
		return strTime;
	}

	/**
	 * 获取当前应用系统的日期
	 * 
	 * @return String 当前应用系统的日期,例如:200722
	 */
	public static String getCurrentDate_YM() {
		String strTime = "-1";
		try {
			final Date date = new Date();
			final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMM");
			strTime = dateFormat.format(date);

		} catch (final Exception e) {
			e.fillInStackTrace();
		}
		return strTime;
	}

	/**
	 * 获取当前应用系统的前一天日期
	 * 
	 * @return String 当前应用系统的前一天日期,例如:20070203
	 */
	public static String getCurrentPrevDate(int delta) {
		String strTime = "-1";
		try {
			final Calendar calendar = Calendar.getInstance();

			calendar.setTime(new Date());

			calendar.add(Calendar.DATE, delta);

			final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
			strTime = dateFormat.format(calendar.getTime());

		} catch (final Exception e) {
			e.fillInStackTrace();
			strTime = "-1";
		}
		return strTime;
	}

	/**
	 * 计算若干个月之后的年月
	 * 
	 * @param beginTime
	 *            开始年月
	 * @param month
	 *            经过月数
	 * @return
	 */
	public static int getMonthsLater(int beginYearMonth, int month) {
		int _year = beginYearMonth / 100;
		final int _month = beginYearMonth - _year * 100;

		if (month > 0) {
			int _tempMon = _month + month; // - 1;
			if (_tempMon > 12) {
				_year = _year + _tempMon / 12;
				_tempMon = _tempMon % 12;
				if (_tempMon == 0) {
					_year = _year - 1;
					_tempMon = 12; // _month;
				}
			}
			return _year * 100 + _tempMon;
		} else if (month < 0) {
			_year = _year - Math.abs(month) / 12;
			int _tempMon = _month - Math.abs(month) % 12;
			if (_tempMon <= 0) {
				_year = _year - 1;
				_tempMon = 12 - Math.abs(_tempMon);
			}
			return _year * 100 + _tempMon;
		} else {
			return beginYearMonth;
		}

	}

	/**
	 * 获取当前应用系统的前一天日期
	 * 
	 * @return String 当前应用系统的前一天日期,例如:20070203
	 */
	public static String getAnyDeltaMonth(String strDate, int delta) {
		String strTime = "-1";

		final int len = strDate.length();

		if (len == 6) {

			strDate = strDate + "01";

		} else if (len == 4) {

			strDate = strDate + "0101";
		}

		try {
			final Calendar calendar = Calendar.getInstance();

			calendar.setTime(new Date());

			calendar.set(Calendar.YEAR, getYearFrmStr(strDate));

			calendar.set(Calendar.MONTH, getMonthFrmStr(strDate) - 1);

			calendar.set(Calendar.DATE, getDayFrmStr(strDate));

			if (len == 6) {
				calendar.add(Calendar.MONTH, delta);
			} else if (len == 8) {
				calendar.add(Calendar.DATE, delta);
			} else if (len == 4) {
				calendar.add(Calendar.YEAR, delta);
			}

			SimpleDateFormat dateFormat = null;

			if (len == 4) {

				dateFormat = new SimpleDateFormat("yyyy");

			} else if (len == 6) {

				dateFormat = new SimpleDateFormat("yyyyMM");

			} else if (len == 8) {

				dateFormat = new SimpleDateFormat("yyyyMMdd");
			}

			strTime = dateFormat.format(calendar.getTime());

		} catch (final Exception e) {
			e.printStackTrace();
			strTime = "-1";
		}
		return strTime;
	}

	/**
	 * 获取当前年月
	 * 
	 * @return
	 */
	public static String getYYYYMM() {
		String strTime = "-1";
		try {
			final Date date = new Date();
			final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMM");
			strTime = dateFormat.format(date);

		} catch (final Exception e) {
			strTime = "-1";
			e.fillInStackTrace();
		}
		return strTime;
	}

	/**
	 * 获取当前年月日
	 * 
	 * @return
	 */
	public static String getYYYYMMdd() {
		String strTime = "-1";
		try {
			final Date date = new Date();
			final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
			strTime = dateFormat.format(date);

		} catch (final Exception e) {
			strTime = "-1";
			e.fillInStackTrace();
		}
		return strTime;
	}

	public static String getCurrentTime() {
		String strTime = "-1";
		try {
			final Date date = new Date();
			final SimpleDateFormat dateFormat = new SimpleDateFormat(
					"yyyyMMddHHmmss");
			strTime = dateFormat.format(date);

		} catch (final Exception e) {
			strTime = "-1";
			e.fillInStackTrace();
		}
		return strTime;
	}

	public static String getyyyyMMddHHmmssSSS() {
		String strTime = "-1";
		try {
			final Date date = new Date();
			final SimpleDateFormat dateFormat = new SimpleDateFormat(
					"yyyyMMddHHmmssSSS");
			strTime = dateFormat.format(date);

		} catch (final Exception e) {
			strTime = "-1";
			e.fillInStackTrace();
		}
		return strTime;
	}

	/**
	 * 获取当前年月日,2004-06-08 05:33:99
	 * 
	 * @return
	 */
	public static String getStryyyyMMddHHmmss() {
		String strTime = "-1";
		try {
			final Date date = new Date();
			final SimpleDateFormat dateFormat = new SimpleDateFormat(
					"yyyy-MM-dd HH:mm:ss");
			strTime = dateFormat.format(date);

		} catch (final Exception e) {
			strTime = "-1";
			e.fillInStackTrace();
		}
		return strTime;
	}

	/**
	 * 获取当前年月日,2004-06-08 05:33:99
	 * 
	 * @return
	 */
	public static String getStryyyyMMddHHmmss(Date date) {
		String strTime = "-1";
		try {

			final SimpleDateFormat dateFormat = new SimpleDateFormat(
					"yyyy-MM-dd HH:mm:ss");
			strTime = dateFormat.format(date);

		} catch (final Exception e) {
			strTime = "-1";
			e.fillInStackTrace();
		}
		return strTime;
	}

	/**
	 * 检查是否数字（不带小数）
	 * 
	 * @param sNumber
	 * @return
	 */
	public static boolean checkNumber(String sNumber) {
		if ("".equals(getTrimString(sNumber))) {
			return false;
		} else {
			try {
				Long.parseLong(sNumber);
				return true;
			} catch (final Exception ex) {
				return false;
			}
		}
	}

	/**
	 * 检查是否数字（带两位小数）
	 * 
	 * @param sNumber
	 * @return
	 */
	public static boolean checkDecimal(String sNumber) {
		if ("".equals(getTrimString(sNumber))) {
			return false;
		} else {
			try {
				Double.parseDouble(sNumber);
				return true;
			} catch (final Exception ex) {
				return false;
			}
		}
	}

	/**
	 * 检查输入日期的合法性
	 * 
	 * @param strDate
	 *            String 输入日期,例如:"20070212"
	 * @return boolean 检查结果
	 */
	public static boolean checkDateFormat(String strDate) {

		if (strDate == null) {
			return false;
		}
		if (strDate.length() != 8) {
			return false;
		} else {
			final String strNum = "1234567890";
			final char[] cStart = strDate.toCharArray();
			for (int i = 0; i < cStart.length; i++) {
				final char c = cStart[i];
				if (strNum.indexOf(c) < 0) {
					return false;
				}
			}
		}
		return true;
	}

	// 检查时刻hh:mm的合法性
	public static boolean checkClockFormat(String strClock) {
		if (strClock == null) {
			return false;
		}

		if (strClock.length() != 4) {
			return false;
		} else {

			// 小时
			final String hour = strClock.substring(0, 2);
			// 分钟
			final String min = strClock.substring(2, strClock.length());

			if (checkNumFormat(hour) == false) {
				return false;
			}

			if (checkNumFormat(min) == false) {
				return false;
			}

			final int iHour = Integer.parseInt(hour);
			if (iHour < 0 || iHour > 23) {
				return false;
			}

			final int iMin = Integer.parseInt(min);
			if (iMin < 0 || iMin > 59) {
				return false;
			}

		}
		return true;
	}

	public static boolean checkNumFormat(String strNum) {

		if (strNum == null) {
			return false;
		}

		final char[] cMin = strNum.toCharArray();
		for (int i = 0; i < cMin.length; i++) {
			final char c = cMin[i];
			if (strNum.indexOf(c) < 0) {
				return false;
			}
		}
		return true;
	}

	/**
	 * 获得当前系统的日期和时刻
	 * 
	 * @return String 当前系统的日期和时刻,例如: 2007-1-29 11:40:54
	 */
	public static String getCurrentDateTimeFormat() {
		final Date date = new Date();
		final DateFormat dateFormat = DateFormat.getDateTimeInstance();
		return dateFormat.format(date);
	}

	/**
	 * 根据输入日期和输入时间,转换成Date类型
	 * 
	 * @param strdate
	 *            String 输入日期
	 * @param strTime
	 *            String 输入时间
	 * @return Date 转换后的Date实例
	 */
	public static Date getDateFormat(String strdate, String strTime) {

		strTime += ":00";

		final DateFormat dateFormat = DateFormat.getDateTimeInstance();
		if (getTrimString(strdate).equals("")) {
			return null;
		}

		final StringBuffer buffer = new StringBuffer();
		buffer.append(strdate.substring(0, 4)).append("-")
				.append(strdate.substring(4, 6)).append("-")
				.append(strdate.substring(6, 8)).append(" ").append(strTime);

		try {
			return dateFormat.parse(buffer.toString());
		} catch (final ParseException e) {
			e.printStackTrace();
		}
		return null;
	}

	public static String FormatSQLDate(Date date) {

		if (date == null) {
			return "";
		}

		String strTime = "()";

		try {

			final SimpleDateFormat dateFormat = new SimpleDateFormat(
					"yyyy-MM-dd");
			strTime = dateFormat.format(date);

		} catch (final Exception e) {
			strTime = "-1";
			e.fillInStackTrace();
		}

		return strTime;
	}

	/**
	 * 根据输入Date类,转换成对应的日期String,例如:20070202
	 * 
	 * @param date
	 *            Date 输入Date类
	 * @return String 日期String
	 */
	public static String FormatDate(Date date) {

		if (date == null) {
			return "";
		}

		// 日期格式化
		final DateFormat dateFormat = DateFormat.getDateInstance();
		String strdate = dateFormat.format(date);

		// 获取年份
		final String year = strdate.substring(0, strdate.indexOf("-"));
		// 去除年份
		strdate = strdate.substring(strdate.indexOf("-") + 1);

		// 获取月份
		String month = strdate.substring(0, strdate.indexOf("-"));
		if (month.length() == 1) {
			month = "0" + month;
		}

		// 获取日期
		String day = strdate.substring(strdate.indexOf("-") + 1);
		if (day.length() == 1) {
			day = "0" + day;
		}

		return year + month + day;
	}

	/**
	 * 格式化输入时间,例如:12点24分, 输入时间为1224,格式化后为12:24
	 * 
	 * @param strTime
	 *            String 输入时间
	 * @return String 格式化时间
	 */
	public static String getTimeFormat(String strTime) {
		if (strTime == null) {
			return "";
		}

		if (strTime.length() != 4) {
			return "";
		} else {

			// 小时
			final String hour = strTime.substring(0, 2);
			// 分钟
			final String min = strTime.substring(2, 4);

			if (checkNumFormat(hour) == false) {
				return "";
			}

			if (checkNumFormat(min) == false) {
				return "";
			}

			final int iHour = Integer.parseInt(hour);
			if (iHour < 0 || iHour > 23) {
				return "";
			}

			final int iMin = Integer.parseInt(min);
			if (iMin < 0 || iMin > 59) {
				return "";
			}
			return hour + ":" + min;
		}
	}

	/**
	 * 截取操作时间方法
	 * 
	 * @param czsj
	 *            String 操作时间,例如:"200702121230"
	 * @return String 截取操作时间的字符串,例如:"20070212"
	 * @throws Exception
	 */
	public static String subCZSJ(String czsj) throws Exception {

		// 检查参数
		final String date = getTrimString(czsj);
		if (date.equals("") || date.length() < 8) {
			return "";
		}

		return date.substring(0, 8);
	}

	public static String getFullDateTime() {
		final SimpleDateFormat dateFormat = (SimpleDateFormat) DateFormat
				.getDateTimeInstance();

		return dateFormat.format(new Date());
	}

	public static String formatFullDateTime(Date date) {
		final SimpleDateFormat dateFormat = (SimpleDateFormat) DateFormat
				.getDateTimeInstance();

		return dateFormat.format(date);
	}

	public static String getStrValue(HttpServletRequest request, String key) {

		if (request == null || key == null) {
			return "";
		}
		return getTrimString(request.getParameter(key));
	}

	public static String getStrValue(HttpSession session, String key) {

		if (session == null || key == null) {
			return "";
		}
		return getTrimString(session.getAttribute(key));
	}

	public static String getStrValue(Hashtable hashtable, String key) {

		if (hashtable == null || key == null) {
			return "";
		}
		return getTrimString(hashtable.get(key));
	}

	public static String getStrValue(Map map, String key) {

		if (map == null || key == null) {
			return "";
		}
		return getTrimString(map.get(key));
	}

	public static String getStrValue(List ltindata, int index) {

		if (ltindata == null || ltindata == null) {
			return "";
		}
		return getTrimString(ltindata.get(index));
	}

	public static String alertInfo(Object strInfo) {
		return "<script>alert('" + getTrimString(strInfo) + "')</script>";
	}

	public static String relocation(Object strInfo) {
		return "<script>document.location.href = \"" + getTrimString(strInfo)
				+ "\"</script>";
	}

	public static String refreshParent() {
		final StringBuffer script = new StringBuffer();
		script.append("<script>")
				.append("window.opener.document.forms[0].submit();")
				.append("window.close();").append("</script>");

		return script.toString();
	}

	public static int getStringInt(String strin) {

		int iret;
		if (strin == null || strin.equals(""))
			iret = 0;
		else
			try {
				iret = Integer.parseInt(strin.trim());
			} catch (final Exception e) {
				iret = 0;
			}
		return iret;
	}

	public static String[] split2(String tempaborts, String dot) {
		// 创建StringTokenizer对象
		final StringTokenizer st = new StringTokenizer(tempaborts, dot);
		// 获取总数
		final int len = st.countTokens();
		final String[] val = new String[len];
		int m = 0;
		// 分割
		while (st.hasMoreTokens()) {
			val[m] = st.nextToken();
			m++;
		}
		return val;
	}

	public static String append(String[] strArrays, String delim) {

		if (strArrays == null)
			return null;

		if (delim == null)
			return null;

		final StringBuffer strb_buff = new StringBuffer();

		for (int i = 0; i < strArrays.length; i++) {
			strb_buff.append(strArrays[i]).append(delim);
		}

		return strb_buff.toString();

	}

	public static String subString(String strin, int len) {

		if (strin == null || strin.equals("")) {
			return "";
		}
		try {
			final int strlen = strin.length();
			if (strlen <= len) {
				return strin;
			} else {
				return strin.substring(0, len) + "...";
			}
		} catch (final Exception ex) {
			ex.printStackTrace();

		}

		return "";
	}

	public static String retError(String strError) {

		// 声明字符缓冲
		final StringBuffer strbuff = new StringBuffer();

		// 组合字符串
		strbuff.append("error[@@#]").append(strError).append("[@@#](END)[@@#]");

		return strbuff.toString();
	}

	public static String NumToStr(String num) {

		final BigDecimal bigDecimal = new BigDecimal(num);
		return bigDecimal.toString();
	}

	public static String getGender(String idno) {

		int sex = 0;
		if (idno.length() < 18) {
			sex = Integer.parseInt(idno.substring(14, 15));
		} else {
			sex = Integer.parseInt(idno.substring(16, 17));
		}
		return (sex % 2) == 1 ? "00" : "01";
	}

	/**
	 * 从公民身份号码获得生日
	 * 
	 * @param idno
	 *            身份证号码
	 * @return int (正确返回yyyymmdd, 错误返回-1)
	 */
	public static String getBirthFromIdno(String idno) {

		if (idno == null) {
			return "-1";
		}

		final int length = idno.length();
		String birthDay = "-1"; // 储存公民身份号码
		if (length == 15 || length == 15 + 1 || length == 15 + 2) { // 公民身份号码为15位
			birthDay = "19" + idno.substring(6, 12);
		} else if (length == 18 || length == 18 + 1) { // 公民身份号码为18位
			birthDay = idno.substring(6, 14);
		} else {
			return "-1";
		}
		return birthDay;

	}

	/**
	 * 从公民身份号码获得生日
	 * 
	 * @param idno
	 *            身份证号码
	 * @return int (正确返回yyyymmdd, 错误返回-1)
	 */
	public static String getBirthYYYYMMFromIdno(String idno) {

		if (idno == null) {
			return "-1";
		}

		final int length = idno.length();
		String birthDay = "-1"; // 储存公民身份号码
		if (length == 15 || length == 15 + 1 || length == 15 + 2) { // 公民身份号码为15位
			birthDay = "19" + idno.substring(6, 10);
		} else if (length == 18 || length == 18 + 1) { // 公民身份号码为18位
			birthDay = idno.substring(6, 12);
		} else {
			return "-1";
		}
		return birthDay;

	}

	/**
	 * 获取两个日期间隔天数
	 * 
	 * @param startDate
	 *            开始日期 YYYYMMDD
	 * @param endDate
	 *            结束日期 YYYYMMDD
	 * @return 间隔天数:有正，有负
	 */
	public static int intervalOrgDays(int startDate, int endDate) {
		int interval = 0;
		final int orgStartDate = startDate;
		final int orgEndDate = endDate;
		int tempDate = 0;
		if (startDate > endDate) {
			tempDate = startDate;
			startDate = endDate;
			endDate = tempDate;
		}

		// 平年月的天数
		final int _monthDays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,
				31 };

		final String _startDate = Integer.toString(startDate);
		final String _endDate = Integer.toString(endDate);

		int _startYear = Integer.parseInt(_startDate.substring(0, 4));
		final int _startMonth = Integer.parseInt(_startDate.substring(4, 6));
		final int _startDay = Integer.parseInt(_startDate.substring(6, 8));

		final int _endYear = Integer.parseInt(_endDate.substring(0, 4));
		final int _endMonth = Integer.parseInt(_endDate.substring(4, 6));
		final int _endDay = Integer.parseInt(_endDate.substring(6, 8));

		// 计算开始年度到当年底的天数
		int _passDay = 0; // 当年已过的天数
		if (_startMonth < 3) {
			for (int index = 0; index < _startMonth - 1; index++) {
				_passDay += _monthDays[index];
			}
			_passDay += _startDay - 1;

			if (isLeapYear(_startYear)) {
				interval = 366 - _passDay;
			} else {
				interval = 365 - _passDay;
			}
		} else {
			for (int index = 0; index < _startMonth - 1; index++) {
				_passDay += _monthDays[index];
			}
			_passDay += _startDay - 1;

			interval = 365 - _passDay;
		}

		// 计算开始下一年度到结束前年度的天数
		if (_startYear == _endYear) { // 同一年
			if (isLeapYear(_startYear)) {
				interval -= 366;
			} else {
				interval = interval - 365;
			}
		}
		_startYear++;
		while (_startYear < _endYear) {
			if (isLeapYear(_startYear)) {
				interval += 366;
			} else {
				interval += 365;
			}
			_startYear++;
		}

		// 计算结束年度的天数
		_passDay = 0;
		if (_endMonth > 3) {
			for (int index = 0; index < _endMonth - 1; index++) {
				_passDay += _monthDays[index];
			}
			_passDay += _endDay;

			if (isLeapYear(_endYear)) {
				interval += (_passDay + 1);
			} else {
				interval += _passDay;
			}
		} else {
			for (int index = 0; index < _endMonth - 1; index++) {
				_passDay += _monthDays[index];
			}
			_passDay += _endDay;

			interval += _passDay;
		}
		if (orgStartDate > orgEndDate) {
			interval = -interval;
		}

		return interval;
	}

	/**
	 * 是否闰年
	 * 
	 * @param CurYear
	 *            年度
	 * @return True - 是闰年； false - 平年
	 */
	public static boolean isLeapYear(int CurYear) {
		boolean _bIsLeap = false;
		// 判定平年闰年
		if (((CurYear % 4 == 0) && (CurYear % 100 != 0))
				|| (CurYear % 400 == 0)) {
			_bIsLeap = true;
		} else {
			_bIsLeap = false;
		}
		return _bIsLeap;
	}

	/**
	 * 根据当前年月，获得上一年月
	 * 
	 * @param yearMonth
	 *            当前年月
	 * @return 上一年月
	 */
	public static String getPreviousMonth(String yearMonth) {

		String PreviousMonth = "";
		int year = new Integer(yearMonth.substring(0, 4)).intValue();
		int month = new Integer(yearMonth.substring(4, 6)).intValue();

		month = month - 1;
		if (month == 0) { // 跨年度
			year = year - 1;
			month = 12;
		}

		if (month < 10) {
			PreviousMonth = String.valueOf(year) + "0" + String.valueOf(month);
		} else {
			PreviousMonth = String.valueOf(year) + String.valueOf(month);
		}

		return PreviousMonth;
	}

	/**
	 * 根据当前年月，获得下一年月
	 * 
	 * @param yearMonth
	 *            当前年月
	 * @return 下一年月
	 */
	public static String getLastMonth(String yearMonth) {
		String LastMonth = "";
		int year = new Integer(yearMonth.substring(0, 4)).intValue();
		int month = new Integer(yearMonth.substring(4, 6)).intValue();
		month = month + 1;
		if (month == 13) { // 跨年度
			year = year + 1;
			month = 1;
		}
		if (month < 10) {
			LastMonth = String.valueOf(year) + "0" + String.valueOf(month);
		} else {
			LastMonth = String.valueOf(year) + String.valueOf(month);
		}
		return LastMonth;
	}

	/**
	 * 在字符串左侧补0
	 * 
	 * @param str
	 *            传入的字数串
	 * @param length
	 *            长度
	 * @return String 左侧补了0的字符串
	 */
	public static String setStringLength(String str, int length) {
		final StringBuffer result = new StringBuffer(length);
		int len = 0;
		if (str == null || str.equals("")) {
			len = 0;
		} else {
			len = str.trim().getBytes().length;
		}
		final int dif = length - len;
		if (dif > 0) {
			for (int i = 0; i < length - len; i++) {
				result.append("0");
			}
		}
		result.append(str);
		return result.toString();
	}

	/**
	 * 在字符串左侧补字符
	 * 
	 * @param str
	 *            传入的字数串
	 * @param length
	 *            长度
	 * @return String 左侧补了字符的字符串
	 */
	public static String setStringBlankLength(String str, int length,
			String blank) {
		final StringBuffer result = new StringBuffer(length);
		int len = 0;
		if (str == null || str.equals("")) {
			len = 0;
		} else {
			len = str.trim().getBytes().length;
		}
		final int dif = length - len;
		if (dif > 0) {
			for (int i = 0; i < length - len; i++) {
				result.append(blank);
			}
		}
		result.append(str);
		return result.toString();
	}

	public static double sub(double v1, double v2) {
		final BigDecimal b1 = new BigDecimal(v1);
		final BigDecimal b2 = new BigDecimal(v2);
		final BigDecimal b3 = new BigDecimal(1);
		final BigDecimal b4 = b1.subtract(b2);
		return Double.parseDouble(String.valueOf(b4.divide(b3, 6,
				BigDecimal.ROUND_HALF_UP)));
	}

	public static String add(double v1, double v2) {

		final BigDecimal b1 = new BigDecimal(v1);
		final BigDecimal b2 = new BigDecimal(v2);
		final BigDecimal b3 = new BigDecimal(1);
		final BigDecimal b4 = b1.add(b2);
		return String.valueOf(b4.divide(b3, 6, BigDecimal.ROUND_HALF_UP));
	}

	/**
	 * 提供（相对）精确的除法运算。当发生除不尽的情况时，由scale参数指 定精度，以后的数字四舍五入。
	 * 
	 * @param v1
	 *            被除数
	 * @param v2
	 *            除数
	 * @param scale
	 *            表示表示需要精确到小数点以后几位。
	 * @return 两个参数的商
	 */
	public static String div(String v1, String v2, int scale) {
		v1 = StoN(v1);
		v2 = StoN(v2);
		if (scale < 0) {
			throw new IllegalArgumentException("参数必须大于0");
		}
		final BigDecimal b1 = new BigDecimal(v1);
		final BigDecimal b2 = new BigDecimal(v2);
		final BigDecimal b3 = new BigDecimal(1);
		final BigDecimal b4 = b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP);
		return String.valueOf(b4.divide(b3, 2, BigDecimal.ROUND_HALF_UP));
	}

	public static String StoN(String str) {
		String sReturn = "";
		if (str == null)
			str = "";
		if (str.trim().equals(""))
			sReturn = "0";
		else
			sReturn = str;
		return sReturn;
	}

	public static String getYYYYMMfromOneDay(int Date) {
		String strYYYYMM = "";

		int tmpYYYYMM = Date;

		strYYYYMM += tmpYYYYMM;

		while (tmpYYYYMM >= 199808) {
			tmpYYYYMM = getMonthsLater(tmpYYYYMM, -1);
			strYYYYMM += "," + tmpYYYYMM;
		}
		;
		return strYYYYMM.toString();
	}

	public static String getCurrentPrevDate() {
		String strTime = "-1";
		try {
			final Calendar calendar = Calendar.getInstance();

			calendar.setTime(new Date());

			calendar.add(Calendar.DATE, -1);

			final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
			strTime = dateFormat.format(calendar.getTime());

		} catch (final Exception e) {
			e.fillInStackTrace();
		}
		return strTime;
	}

	/**
	 * 全角转换成半角
	 * 
	 * @param sValue
	 * @return
	 */
	public static String getQj2Bj(String sValue) {
		final String[] sArrQj = { "０", "１", "２", "３", "４", "５", "６", "７", "８",
				"９", "（", "）", "－", "Ａ", "Ｂ", "Ｃ", "Ｄ", "Ｅ", "Ｆ", "Ｇ", "Ｈ",
				"Ｉ", "Ｊ", "Ｋ", "Ｌ", "Ｍ", "Ｎ", "Ｏ", "Ｐ", "Ｑ", "Ｒ", "Ｓ", "Ｔ",
				"Ｕ", "Ｖ", "Ｗ", "Ｘ", "Ｙ", "Ｚ" };
		final String[] sArrBj = { "0", "1", "2", "3", "4", "5", "6", "7", "8",
				"9", "(", ")", "-", "A", "B", "C", "D", "E", "F", "G", "H",
				"I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
				"U", "V", "W", "X", "Y", "Z" };
		String sNewString = "";
		for (int i = 0; i < sValue.length(); i++) {
			final char chObj = sValue.charAt(i);
			boolean bolQj = false;
			for (int j = 0; j < sArrQj.length; j++) {
				if (sArrQj[j].equals(String.valueOf(chObj))) {
					sNewString += sArrBj[j];
					bolQj = true;
					break;
				}
			}
			if (!bolQj) {
				sNewString += chObj;
			}
		}
		return sNewString;
	}

	public static String handleNull(Object obj) {
		if (obj == null)
			return "";
		if (obj.toString().equals("null"))
			return "";
		if (obj.toString().equals("-=选择=-"))
			return "";
		if (obj.toString().equals("1900-01-01"))
			return "";
		return obj.toString().trim();
	}

	/*
	 * 生成15、16、18位身份证号
	 */
	public static Map genSfzh(String idNo) {
		String idNo18;
		String idNo16;
		String idNo15;
		final Map map = new HashMap();
		final int len = idNo.length();
		if (len == 18) {
			idNo18 = idNo;
			idNo15 = IDHelper.IDCard18to15(idNo);
			idNo16 = idNo15 + "0";
		} else if (len == 16) {
			idNo16 = idNo;
			idNo15 = idNo.substring(0, 15);
			idNo18 = IDHelper.IDCard15to18(idNo15);
		} else if (len == 15) {
			idNo15 = idNo;
			idNo16 = idNo15 + "0";
			idNo18 = IDHelper.IDCard15to18(idNo15);
		} else {
			idNo15 = idNo;
			idNo16 = idNo;
			idNo18 = idNo;
		}

		map.put("idNo15", idNo15);
		map.put("idNo16", idNo16);
		map.put("idNo18", idNo18);
		return map;
	}

	/**
	 * 计算两个年月之间相隔的月份
	 * 
	 * @param StartDate
	 *            开始的年月(int YYYYMM)
	 * @param EndDate
	 *            结束的年月(int YYYYMM)
	 * @return 计算日期相隔的月份
	 */
	public static int getDifferenceMonth(int startMonth, int endMonth) {
		final int _iYearS = startMonth / 100;
		final int _iYearE = endMonth / 100;
		final int _iMonthS = startMonth - _iYearS * 100;
		final int _iMonthE = endMonth - _iYearE * 100;
		int _iMonthSum = 0;
		final int _iYearSum = _iYearE - _iYearS;
		if (_iYearSum == 0) {
			_iMonthSum = _iMonthE - _iMonthS;
		}
		if (_iYearSum >= 1) {
			_iMonthSum = (12 - _iMonthS) + _iMonthE + 12 * (_iYearSum - 1);
		}
		return _iMonthSum;
	}

	public static String moneyFormatStr2(String strtotal) {
		String ret = "";
		try {
			double total = Double.parseDouble(strtotal);
			total = round(total, 2);
			final java.text.DecimalFormat decimalFormat = new java.text.DecimalFormat(
					"####0.00");
			ret = decimalFormat.format(Math.round(total * 100) / (double) 100);
		} catch (final Exception ex) {
			ex.printStackTrace();
			ret = "0.00";
		}
		return ret;
	}

	public static String moneyFormatStr(String strtotal) {
		String ret = "";
		try {
			double total = Double.parseDouble(strtotal);
			total = round(total, 2);
			final java.text.DecimalFormat decimalFormat = new java.text.DecimalFormat(
					"###,###,###.00");
			ret = decimalFormat.format(Math.round(total * 100) / (double) 100);
		} catch (final Exception ex) {
			ex.printStackTrace();
			ret = "0.00";
		}
		return ret;
	}

	public static String moneyFormatStr(double total) {
		String ret = "";
		try {
			total = round(total, 2);
			final java.text.DecimalFormat decimalFormat = new java.text.DecimalFormat(
					"###,###.00");
			ret = decimalFormat.format(Math.round(total * 100) / (double) 100);
		} catch (final Exception ex) {
			ex.printStackTrace();
			ret = "0.00";
		}
		return ret;
	}

	/************************ 正则表达式验证 方法 start ***************************/
	/**
	 * 验证手机号码（支持国际格式，+86135xxxx...（中国内地），+00852137xxxx...（中国香港））
	 * 
	 * @param mobile
	 *            移动、联通、电信运营商的号码段
	 *            <p>
	 *            移动的号段：134(0-8)、135、136、137、138、139、147（预计用于TD上网卡）
	 *            、150、151、152、157（TD专用）、158、159、187（未启用）、188（TD专用）
	 *            </p>
	 *            <p>
	 *            联通的号段：130、131、132、155、156（世界风专用）、185（未启用）、186（3g）
	 *            </p>
	 *            <p>
	 *            电信的号段：133、153、180（未启用）、189
	 *            </p>
	 * @return 验证成功返回true，验证失败返回false
	 */
	public static boolean checkMobile(String value) {
		final String regex = "(\\+\\d+)?1[3458]\\d{9}$";
		return Pattern.matches(regex, value);
	}

	/**
	 * 匹配中国邮政编码
	 * 
	 * @param postcode
	 *            邮政编码
	 * @return 验证成功返回true，验证失败返回false
	 */
	public static boolean checkPostcode(String postcode) {
		final String regex = "[1-9]\\d{5}";
		return Pattern.matches(regex, postcode);
	}

	/**
	 * 验证Email
	 * 
	 * @param email
	 *            email地址，格式：zhangsan@sina.com，zhangsan@xxx.com.cn，xxx代表邮件服务商
	 * @return 验证成功返回true，验证失败返回false
	 */
	public static boolean checkEmail(String email) {
		final String regex = "\\w+@\\w+\\.[a-z]+(\\.[a-z]+)?";
		return Pattern.matches(regex, email);
	}

	/**
	 * 验证身份证号码
	 * 
	 * @param idCard
	 *            居民身份证号码15位或18位，最后一位可能是数字或字母
	 * @return 验证成功返回true，验证失败返回false
	 */
	public static boolean checkIdCard(String idCard) {
		final String regex = "[1-9]\\d{13,16}[a-zA-Z0-9]{1}";
		return Pattern.matches(regex, idCard);
	}

	/**
	 * 验证固定电话号码
	 * 
	 * @param phone
	 *            电话号码，格式：国家（地区）电话代码 + 区号（城市代码） + 电话号码，如：+8602085588447
	 *            <p>
	 *            <b>国家（地区） 代码 ：</b>标识电话号码的国家（地区）的标准国家（地区）代码。它包含从 0 到 9
	 *            的一位或多位数字， 数字之后是空格分隔的国家（地区）代码。
	 *            </p>
	 *            <p>
	 *            <b>区号（城市代码）：</b>这可能包含一个或多个从 0 到 9 的数字，地区或城市代码放在圆括号——
	 *            对不使用地区或城市代码的国家（地区），则省略该组件。
	 *            </p>
	 *            <p>
	 *            <b>电话号码：</b>这包含从 0 到 9 的一个或多个数字
	 *            </p>
	 * @return 验证成功返回true，验证失败返回false
	 */
	public static boolean checkPhone(String phone) {
		final String regex = "(\\+\\d+)?(\\d{3,4}\\-?)?\\d{7,8}$";
		return Pattern.matches(regex, phone);
	}

	/**
	 * 验证整数（正整数和负整数）
	 * 
	 * @param digit
	 *            一位或多位0-9之间的整数
	 * @return 验证成功返回true，验证失败返回false
	 */
	public static boolean checkDigit(String digit) {
		final String regex = "\\-?[1-9]\\d+";
		return Pattern.matches(regex, digit);
	}

	/**
	 * 验证整数和浮点数（正负整数和正负浮点数）
	 * 
	 * @param decimals
	 *            一位或多位0-9之间的浮点数，如：1.23，233.30
	 * @return 验证成功返回true，验证失败返回false
	 */
	public static boolean checkDecimals(String decimals) {
		final String regex = "\\-?[1-9]\\d+(\\.\\d+)?";
		return Pattern.matches(regex, decimals);
	}

	/**
	 * 验证空白字符
	 * 
	 * @param blankSpace
	 *            空白字符，包括：空格、\t、\n、\r、\f、\x0B
	 * @return 验证成功返回true，验证失败返回false
	 */
	public static boolean checkBlankSpace(String blankSpace) {
		final String regex = "\\s+";
		return Pattern.matches(regex, blankSpace);
	}

	/**
	 * 验证中文
	 * 
	 * @param chinese
	 *            中文字符
	 * @return 验证成功返回true，验证失败返回false
	 */
	public static boolean checkChinese(String chinese) {
		final String regex = "^[\u4E00-\u9FA5]+$";
		return Pattern.matches(regex, chinese);
	}

	/**
	 * 验证日期（年月日）
	 * 
	 * @param birthday
	 *            日期，格式：1992-09-03，或1992.09.03
	 * @return 验证成功返回true，验证失败返回false
	 */
	public static boolean checkBirthday(String birthday) {
		final String regex = "[1-9]{4}([-./])\\d{1,2}\\1\\d{1,2}";
		return Pattern.matches(regex, birthday);
	}

	/**
	 * 验证URL地址
	 * 
	 * @param url
	 *            格式：http://blog.csdn.net:80/xyang81/article/details/7705960? 或
	 *            http://www.csdn.net:80
	 * @return 验证成功返回true，验证失败返回false
	 */
	public static boolean checkURL(String url) {
		final String regex = "(https?://(w{3}\\.)?)?\\w+\\.\\w+(\\.[a-zA-Z]+)*(:\\d{1,5})?(/\\w*)*(\\??(.+=.*)?(&.+=.*)?)?";
		return Pattern.matches(regex, url);
	}

	/**
	 * 匹配IP地址(简单匹配，格式，如：192.168.1.1，127.0.0.1，没有匹配IP段的大小)
	 * 
	 * @param ipAddress
	 *            IPv4标准地址
	 * @return 验证成功返回true，验证失败返回false
	 */
	public static boolean checkIpAddress(String ipAddress) {
		final String regex = "[1-9](\\d{1,2})?\\.(0|([1-9](\\d{1,2})?))\\.(0|([1-9](\\d{1,2})?))\\.(0|([1-9](\\d{1,2})?))";
		return Pattern.matches(regex, ipAddress);
	}

	/**
	 * * 检查浮点数 * @param num * @param type "0+":非负浮点数 "+":正浮点数 "-0":非正浮点数
	 * "-":负浮点数 "":浮点数 * @return
	 * */
	public static boolean checkFloat(String num, String type) {
		String eL = "";
		if (type.equals("0+"))
			eL = "^\\d+(\\.\\d+)?$";// 非负浮点数
		else if (type.equals("+"))
			eL = "^((\\d+\\.\\d*[1-9]\\d*)|(\\d*[1-9]\\d*\\.\\d+)|(\\d*[1-9]\\d*))$";// 正浮点数
		else if (type.equals("-0"))
			eL = "^((-\\d+(\\.\\d+)?)|(0+(\\.0+)?))$";// 非正浮点数
		else if (type.equals("-"))
			eL = "^(-((\\d+\\.\\d*[1-9]\\d*)|(\\d*[1-9]\\d*\\.\\d+)|(\\d*[1-9]\\d*)))$";// 负浮点数
		else
			eL = "^(-?\\d+)(\\.\\d+)?$";// 浮点数
		final Pattern p = Pattern.compile(eL);
		final Matcher m = p.matcher(num);
		final boolean b = m.matches();
		return b;
	}

	/**
	 * * 检查整数 * @param num * @param type "0+":非负整数 "+":正整数 "-0":非正整数 "-":负整数
	 * "":整数 * @return
	 * */
	public static boolean checkNumber(String num, String type) {
		String eL = "";
		if (type.equals("0+"))
			eL = "^\\d+$";// 非负整数
		else if (type.equals("+"))
			eL = "^\\d*[1-9]\\d*$";// 正整数
		else if (type.equals("-0"))
			eL = "^((-\\d+)|(0+))$";// 非正整数
		else if (type.equals("-"))
			eL = "^-\\d*[1-9]\\d*$";// 负整数
		else
			eL = "^-?\\d+$";// 整数
		final Pattern p = Pattern.compile(eL);
		final Matcher m = p.matcher(num);
		final boolean b = m.matches();
		return b;
	}

	/************************ 正则表达式验证 方法 end *****************************/

	/****
	 * 复制object对象属性（将aClass对象 属性 复制到 bClass 对象的属性）
	 * 
	 * @param aClass
	 * @param bClass
	 * @return 返回 复制后的 bClass 对象
	 */
	public static Object copyObjectFileds(Object aClass, Object bClass)
			throws Exception {
		final Field[] fields = aClass.getClass().getFields();
		for (int i = 0; i < fields.length; i++) {
			final String name = fields[i].getName();
			System.out.println(name + "=============name=============");
			final Field field = bClass.getClass().getField(name);
			field.set(bClass, fields[i].get(aClass));
		}
		return bClass;
	}

	public static void main(String[] args) {
		boolean flg = checkMobile("15992638631");
		System.out.println("手机号码(15992638631)--" + flg);
		flg = checkPostcode("342102");
		System.out.println("邮政编码(519000)--" + flg);
		flg = checkEmail("changyuan126@163.com");
		System.out.println("邮箱(changyuan126@163.com)--" + flg);
		flg = checkIdCard("360726198904070919");
		System.out.println("身份证(360726198904070919)--" + flg);
		flg = checkFloat("5.12", "0+");
		System.out.println("数字(dddd)--" + flg);
		/*
		 * String []strs = new String[]{"a","b","c"};
		 * System.out.println(converToString(strs,","));; List<String> list =
		 * new ArrayList<String>(); list.add("a"); list.add("b"); list.add("c");
		 * System.out.println(converToString(list,"!"));; String ss =
		 * "a1,b1,c1"; strs = stringAnalytical(ss,","); for(int
		 * i=0;i<strs.length;i++){
		 * System.out.println(strs[i]+"=========strs========="); } list =
		 * stringAnalyticalList(ss,","); for(String s:list){
		 * System.out.println(s+"===============list=============="); }
		 */
	}
}
